<?php

namespace App\Task;

use App\Job\CashJob;
use App\Job\CheckPaid;
use App\Model\Device;
use App\Model\Distributors;
use Hyperf\AsyncQueue\Driver\DriverFactory;
use Hyperf\Context\ApplicationContext;
use Hyperf\Crontab\Annotation\Crontab;

#[Crontab(rule: "0 8 * * *", name: "DeviceNotOnlineTask", callback: "execute", memo: "每天早上八点自动提现")]
class AutoCashTask
{
    public function execute(): void
    {
        $list = Distributors::query()->where('balance', '>', 0)
            ->where('settlement_type',Distributors::SETTLEMENT_TYPE_ONE_DAY)
            ->whereNotNull('settle_account_id')
            ->get(['id']);
        $driver = ApplicationContext::getContainer()->get(DriverFactory::class)->get('auto-cash');
        foreach($list as $item){
            $driver->push(new CashJob($item->id));
        }

    }
}
